package model
{
	import flash.display.MovieClip;
	import flash.geom.Rectangle;
	import flash.printing.PrintJob;

	public class Print
	{
		public function Print()
		{
		}
		
		public function printMovieClip(clip:MovieClip) {
			
			var printJob:PrintJob = new PrintJob();
			var numPages:int = 0;
			var printArea:Rectangle;
			var printHeight:Number;
			var printY:int = 0;
			
			if ( printJob.start() ) {
				
				/* Resize movie clip to fit within page width */
				if (clip.width > printJob.pageWidth) {
					clip.width = printJob.pageWidth;
					clip.scaleY = clip.scaleX;
				}
				
				/* Store reference to print area in a new variable! Will save on scaling calculations later... */
				printArea = new Rectangle(0, 0, printJob.pageWidth/clip.scaleX, printJob.pageHeight/clip.scaleY);
				
				numPages = Math.ceil(clip.height / printJob.pageHeight);
				
				/* Add pages to print job */
				for (var i:int = 0; i < numPages; i++) {
					printJob.addPage(clip, printArea);
					printArea.y += printArea.height;
				}
				
				/* Send print job to printer */
				printJob.send();
				
				/* Delete job from memory */
				printJob = null;
				
			}
			
		}

	}
}